<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
	<link rel="icon" href="https://www.cslg.edu.cn/favicon.ico"/>
	<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" crossorigin="anonymous">
	<link rel="stylesheet" th:href="@{/css/global.css}" />
	<link rel="stylesheet" th:href="@{/css/discuss-detail.css}" />
	<title>常理工学生新闻网-资讯详情</title>
</head>
<body>
<div class="nk-container">
	<!-- 头部 -->
	<header class="bg-dark sticky-top" th:replace="index::header"></header>
	<!-- 内容 -->
	<div class="main">
		<!-- 资讯详情 -->
		<div class="container">
			<!-- 标题 -->
			<h6 class="mb-4">
				<img src="https://static.nowcoder.com/images/img/icons/ico-discuss.png"/>
				<span th:utext="${post.title}">这是一条资讯的标题</span>
				<div class="float-right">
					<input type="hidden" id="postId" th:value="${post.id}">
					<button type="button" class="btn btn-danger btn-sm" id="topBtn"
							th:text="${post.type==1?'取消置顶':'置顶'}" sec:authorize="hasAnyAuthority('moderator')">置顶</button>
					<button type="button" class="btn btn-danger btn-sm" id="wonderfulBtn"
							th:text="${post.status==1?'取消加精':'加精'}" sec:authorize="hasAnyAuthority('moderator')">加精</button>
					<button type="button" class="btn btn-danger btn-sm" id="deleteBtn"
							sec:authorize="hasAnyAuthority('admin')">删除</button>
				</div>
			</h6>
			<!-- 发布者 -->
			<div class="media pb-3 border-bottom">
				<a th:href="@{|/user/profile/${user.id}|}">
					<img th:src="${user.headerUrl}" class="align-self-start mr-4 rounded-circle user-header" alt="用户头像" >
				</a>
				<div class="media-body">
					<div class="mt-0 text-warning" th:utext="${user.username}">张三</div>
					<div class="text-muted mt-3">
						发布于 <b th:text="${#dates.format(post.createTime,'yyyy-MM-dd HH:mm:ss')}">2022-04-15 15:32:18</b>
						<ul class="d-inline float-right">
							<li class="d-inline ml-2">
								<a href="#javascript:;" th:onclick="|like(this,1,${post.id},${post.userId},${post.id});|" class="text-primary">
									<b th:text="${likeStatus==1?'已赞':'赞'}">赞</b> <i th:text="${likeCount}">1</i>
								</a>
							</li>
							<li class="d-inline ml-2">|</li>
							<li class="d-inline ml-2"><a href="#replyform" class="text-primary">评论 <i th:text="${post.commentCount}"></i></a></li>
						</ul>
					</div>
				</div>
			</div>
			<!-- 正文 -->
			<div class="mt-4 mb-3 content" th:utext="${post.content}">
				只是一条样例
			</div>
		</div>
		<!-- 评论 -->
		<div class="container mt-3">
			<!-- 评论数量 -->
			<div class="row">
				<div class="col-8">
					<h6><b class="square"></b> <i th:text="${post.commentCount}">30</i>条评论</h6>
				</div>
				<div class="col-4 text-right">
					<a href="#replyform" class="btn btn-primary btn-sm">&nbsp;&nbsp;评&nbsp;&nbsp;论&nbsp;&nbsp;</a>
				</div>
			</div>
			<!-- 回复列表 -->
			<ul class="list-unstyled mt-4">
				<!-- 评论，以此为模板循环 -->
				<li class="media pb-3 pt-3 mb-3 border-bottom" th:each="cvo:${comments}">
					<a th:href="@{|/user/profile/${cvo.user.id}|}">
						<img th:src="${cvo.user.headerUrl}" class="align-self-start mr-4 rounded-circle user-header" alt="用户头像" >
					</a>
					<div class="media-body">
						<div class="mt-0">
							<span class="font-size-12 text-success" th:utext="${cvo.user.username}">一个测试员</span>
							<span class="badge badge-secondary float-right floor">
									<!-- 楼层数，thymeleaf会提供一个隐含的状态对象，可以通过它获取循环次数 -->
									<i th:text="${page.offset + cvoStat.count}">1</i>
								</span>
						</div>
						<div class="mt-2" th:utext="${cvo.comment.content}">
							这是一条评论
						</div>
						<div class="mt-4 text-muted font-size-12">
							<span>发布于 <b th:text="${#dates.format(cvo.comment.createTime,'yyyy-MM-dd HH:mm:ss')}">2022-04-15 15:32:18</b></span>
							<ul class="d-inline float-right">
								<li class="d-inline ml-2">
									<a href="#javascript:;" th:onclick="|like(this,2,${cvo.comment.id},${cvo.comment.userId},${post.id});|" class="text-primary">
										<b th:text="cvo.likeStatus==1?'已赞':'赞'">赞</b> (<i th:text="${cvo.likeCount}">1</i>)
									</a>
								</li>
								<li class="d-inline ml-2">|</li>
								<li class="d-inline ml-2"><a th:href="|#huifu-${cvoStat.count + cvo.comment.id}|"
															 data-toggle="collapse" class="text-primary">回复(<i th:text="${cvo.replyCount}"></i>)</a></li>
							</ul>
						</div>
						<!-- 回复列表 -->
						<!-- 没有回复时不显示回复框 -->
						<ul th:id="|huifu-${cvoStat.count + cvo.comment.id}|"
							th:class="|list-unstyled mt-4 bg-gray p-3 font-size-12 text-muted ${cvo.replyCount>0?'':'collapse'}|">
							<!-- 对评论的回复，循环 -->
							<li class="pb-3 pt-3 mb-3 border-bottom" th:each="rvo:${cvo.replys}">
								<div>
									<!-- target为null，说明没有人回复该回复，既" a：" 而不是 "b 回复 a：" -->
									<span th:if="${rvo.target==null}">
										<b class="text-info" th:text="${rvo.user.username}">张三</b>:&nbsp;&nbsp;
									</span>
									<!-- target不为null，则显示"b 回复 a：" -->
									<span th:if="${rvo.target!=null}">
										<i class="text-info" th:text="${rvo.user.username}">李四</i>&nbsp;回复
										<b class="text-info" th:text="${rvo.target.username}">张三</b>:&nbsp;&nbsp;
									</span>
									<span th:utext="${rvo.reply.content}">进行一个楼中楼回复的测试~</span>
								</div>
								<div class="mt-3">
									<span th:text="${#dates.format(rvo.reply.createTime,'yyyy-MM-dd HH:mm:ss')}">2022-04-15 15:32:18</span>
									<ul class="d-inline float-right">
										<li class="d-inline ml-2">
											<a href="javascript:;" th:onclick="|like(this,2,${rvo.reply.id},${rvo.reply.userId},${post.id});|" class="text-primary">
												<b th:text="rvo.likeStatus==1?'已赞':'赞'">赞</b> (<i th:text="${rvo.likeCount}">1</i>)
											</a>
										</li>
										<li class="d-inline ml-2">|</li>
										<!-- 回复楼中楼，回复按钮和回复框相匹配 -->
										<li class="d-inline ml-2"><a th:href="|#huifu-${rvoStat.count}|" data-toggle="collapse" class="text-primary">回复</a></li>
									</ul>
									<!-- 生成id:huifu-1、huifu-2...用于匹配回复框 -->
									<div th:id="|huifu-${rvoStat.count}|" class="mt-4 collapse">
										<form method="post" th:action="@{|/comment/add/${post.id}|}">
											<div>
												<input type="text" name="content" class="input-size" th:placeholder="|回复${rvo.user.username}|"/>
												<input type="hidden" name="entityType" value="2"/>
												<input type="hidden" name="entityId" th:value="${cvo.comment.id}"/>
												<input type="hidden" name="targetId" th:value="${rvo.user.id}">
											</div>
											<div class="text-right mt-2">
												<button type="submit" class="btn btn-primary btn-sm" onclick="">&nbsp;&nbsp;回&nbsp;&nbsp;复&nbsp;&nbsp;</button>
											</div>
										</form>
									</div>
								</div>
							</li>

							<!-- 回复输入框 -->
							<li class="pb-3 pt-3">
								<form method="post" th:action="@{|/comment/add/${post.id}|}">
									<div>
										<input type="text" class="input-size" name="content" placeholder="请友善交流！"/>
										<input type="hidden" name="entityType" value="2"/>
										<input type="hidden" name="targetId" th:value="${cvo.user.id}">
										<input type="hidden" name="entityId" th:value="${cvo.comment.id}"/>
									</div>
									<div class="text-right mt-2">
										<button type="submit" class="btn btn-primary btn-sm" onclick="">&nbsp;&nbsp;回&nbsp;&nbsp;复&nbsp;&nbsp;</button>
									</div>
								</form>
							</li>
						</ul>
					</div>
				</li>

			</ul>
			<!-- 分页 -->
			<nav class="mt-5" th:replace="index::pagination"></nav>
		</div>
		<!-- 评论输入 -->
		<div class="container mt-3">
			<form class="replyform" method="post" th:action="@{|/comment/add/${post.id}|}">
				<p class="mt-3">
					<a id="replyform"></a>
					<textarea placeholder="请友善发言，心平气和地交流!" name="content"></textarea>
					<input type="hidden" name="entityType" value="1"/>
					<input type="hidden" name="entityId" th:value="${post.id}"/>
				</p>
				<p class="text-right">
					<button type="submit" class="btn btn-primary btn-sm">&nbsp;&nbsp;评&nbsp;&nbsp;论&nbsp;&nbsp;</button>
				</p>
			</form>
		</div>
	</div>

	<!-- 尾部 -->
	<footer class="bg-dark" th:replace="index::bottom"></footer>
</div>
<script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-3.5.1.min.js" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" crossorigin="anonymous"></script>
<script th:src="@{/js/global.js}"></script>
<script th:src="@{/js/discuss.js}"></script>
</body>
</html>
